<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/index3.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.2.1.js"></script>
    <script src="${pageContext.request.contextPath}/static/My97DatePicker/WdatePicker.js"></script>
</head>

<body>
<form action="zhuce" method="post">
    账号:<input type="text" name="zhanghao"><br>
    显示名称:<input type="text" name="xianming"><br>
    真实姓名:<input type="text" name="zhengming"><br>
    头像:<input type="text" name="img">
        <input type="file" onchange="photo(this)"><br>
    身份证号:<input type="text" name="card" onblur="sf()"><br>
    年龄:<input type="text" name="age"><br>
    手机号1:<input type="text" name="phone1"><br>
    手机号2:<input type="text" name="phone2"><br>
    注册日期:<input type="text" name="date" onclick="WdatePicker()"><br>
    密码:<input type="text" name="password"><br>
    <input type="button" value="注册" onclick="zc()">
</form>
<script>
   function sf() {
      var card=$('[name="card"]').val();
      var zz=/^\d{17}(X|x|\d)$/;
      if(zz.test(card)){
          var nian=card.substring(6,10);
          alert(nian)
          var date=new Date();
         var date1= new Date(nian);
         $('[name="age"]').val(date.getFullYear()- date1.getFullYear());
      }
   }
   function photo(obj) {
   var fromdate= new FormData();
   fromdate.append("file",obj.files[0]);
   $.ajax({
       url:"photo",
       type:"post",
       data:fromdate,
       contentType:false,
       processData:false,
       success:function (url) {
        $('[name="img"]').val(url);
       }
   })
   }
   function zc() {
      zz=/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      var phone1=$('[name="phone1"]').val();
      if(!zz.test(phone1)){
          alert("1不合规定")
          return;
      }
      var phone2=$('[name="phone2"]').val();
      if(!zz.test(phone2)){
          alert("2不合规定")
          return;
      }
      $('form').submit();
   }
</script>
</body>
</html>
